package com.wind.taobao.api.jianghu.convert
{
	import com.wind.taobao.api.jianghu.model.SpaceAlbum;
	import com.wind.taobao.core.util.TaobaoConstants;

	import mx.collections.ArrayCollection;


	/**
	 * SpaceAlbum 转换器
	 * @author fxy
	 *
	 */
	public class SpaceAlbumConvert
	{
		/**
		 * 转换SpaceAlbum集合
		 */
		public static function convertSpaceAlbums(value:Object, type:String="json"):ArrayCollection
		{
			var spaceAlbums:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							spaceAlbums.addItem(convertSpaceAlbum((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return spaceAlbums;
		}

		/**
		 * 转换SpaceAlbum
		 */
		public static function convertSpaceAlbum(value:Object, type:String="json"):SpaceAlbum
		{
			var spaceAlbum:SpaceAlbum=new SpaceAlbum();
			if (value == null)
				return spaceAlbum;
			if (type == TaobaoConstants.XML)
			{
				spaceAlbum=convertXMLToSpaceAlbum(XML(value), spaceAlbum);
			}
			else
			{
				spaceAlbum=convertJSONToSpaceAlbum(value, spaceAlbum);
			}
			return spaceAlbum;
		}

		/**
		 * JSON转换为SpaceAlbum
		 */
		private static function convertJSONToSpaceAlbum(json:Object, spaceAlbum:SpaceAlbum):SpaceAlbum
		{
			if (json.hasOwnProperty(TaobaoConstants.ALBUM_ID))
			{
				spaceAlbum.album_id=json[TaobaoConstants.ALBUM_ID];
			}
			if (json.hasOwnProperty(TaobaoConstants.NAME))
			{
				spaceAlbum.name=json[TaobaoConstants.NAME];
			}
			if (json.hasOwnProperty(TaobaoConstants.TYPE))
			{
				spaceAlbum.type=json[TaobaoConstants.TYPE];
			}
			if (json.hasOwnProperty(TaobaoConstants.MEMO))
			{
				spaceAlbum.memo=json[TaobaoConstants.MEMO];
			}
			if (json.hasOwnProperty(TaobaoConstants.COVER_PATH))
			{
				spaceAlbum.cover_path=json[TaobaoConstants.COVER_PATH];
			}
			if (json.hasOwnProperty(TaobaoConstants.PIC_COUNT))
			{
				spaceAlbum.pic_count=json[TaobaoConstants.PIC_COUNT];
			}
			return spaceAlbum;
		}

		/**
		 * XML转换为SpaceAlbum
		 */
		private static function convertXMLToSpaceAlbum(value:XML, spaceAlbum:SpaceAlbum):SpaceAlbum
		{
			return spaceAlbum;
		}

	}
}